<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.jpg">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"matian.connorma.cn","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="zabbix提供了监控与告警的全套解决方案，在许多大型企业进行了深度实践，功能强大、产品成熟而稳定 选用5.0.4版本，主要的组件有：  zabbix-server，拉取&#x2F;接收zabbix-agent的数据，计算触发器条件、向用户发送通知等核心功能 zabbix-agent，客户端，收集本地监控项数据，并通过主动&#x2F;被动方式发送到zabbix-server zabbix-prox">
<meta property="og:type" content="article">
<meta property="og:title" content="zabbix的部署">
<meta property="og:url" content="http://matian.connorma.cn/c8a6c539.html">
<meta property="og:site_name" content="马天">
<meta property="og:description" content="zabbix提供了监控与告警的全套解决方案，在许多大型企业进行了深度实践，功能强大、产品成熟而稳定 选用5.0.4版本，主要的组件有：  zabbix-server，拉取&#x2F;接收zabbix-agent的数据，计算触发器条件、向用户发送通知等核心功能 zabbix-agent，客户端，收集本地监控项数据，并通过主动&#x2F;被动方式发送到zabbix-server zabbix-prox">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-01-17T06:45:54.000Z">
<meta property="article:modified_time" content="2024-04-26T11:48:37.396Z">
<meta property="article:author" content="马天">
<meta property="article:tag" content="zabbix">
<meta property="article:tag" content="监控">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://matian.connorma.cn/c8a6c539.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>zabbix的部署 | 马天</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">马天</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://matian.connorma.cn/c8a6c539.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="马天">
      <meta itemprop="description" content="程序猿">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="马天">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          zabbix的部署
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-01-17 14:45:54" itemprop="dateCreated datePublished" datetime="2019-01-17T14:45:54+08:00">2019-01-17</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%9B%91%E6%8E%A7/" itemprop="url" rel="index"><span itemprop="name">监控</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>zabbix提供了监控与告警的全套解决方案，在许多大型企业进行了深度实践，功能强大、产品成熟而稳定</p>
<p>选用5.0.4版本，主要的组件有：</p>
<ul>
<li>zabbix-server，拉取&#x2F;接收zabbix-agent的数据，计算触发器条件、向用户发送通知等核心功能</li>
<li>zabbix-agent，客户端，收集本地监控项数据，并通过主动&#x2F;被动方式发送到zabbix-server</li>
<li>zabbix-proxy，可选，负责从一个或多个受监控设备采集监控数据并将信息发送到zabbix-server，以分担zabbix-server的压力</li>
</ul>
<p>此外，根据选用的部署组件版本，zabbix-server如果不包含web功能，还需要部署zabbix-web。zabbix使用Mysql关系型数据库作为底层存储（可选mysql、postgresql、sqlite等），在数据量大的时候对数据库的压力较大，限制了大规模集群中 zabbix 的应用，对告警信息汇总运算时性能较差；并且，zabbix为监控主机、网络设备等基础设置而设计，对于容器监控等场景，zabbix只能通过集成定制化脚本的方式实现且功能有限，在云原生环境下的应用受到限制</p>
<span id="more"></span>

<p>本次部署使用的机器：</p>
<ul>
<li>10.70.20.33，使用docker部署zabbix-server、zabbix-web，部署mysql-5.7</li>
<li>10.70.20.20，部署zabbix-agent</li>
</ul>
<h2 id="mysql部署与配置"><a href="#mysql部署与配置" class="headerlink" title="mysql部署与配置"></a>mysql部署与配置</h2><p>选用mysql-5.7作为zabbix底层存储</p>
<p>建议为zabbix部署单独的mysql，因为zabbix对数据库压力较大，尤其是执行housekeeper的时候；并且，监控数据并不敏感，mysql不必使用主从复制或者备份等手段，也减少了性能损耗和空间占用</p>
<p>mysql-5.7部署具体可以参考<a target="_blank" rel="noopener" href="https://gitee.com/connormma/quick_launch_tools/blob/master/mysql/linux_amd64/mysql_install.sh">quick_launch_tools</a>仓库提供的mysql安装脚本</p>
<p>使用mysql客户端连接到数据库，创建zabbix使用的用户zabbix，指定具有zabbix这一db下的权限（zabbix数据库下将在zabbix-server启动中自动创建数据表）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 创建zabbix数据库，注意character及collate</span></span><br><span class="line"><span class="keyword">create</span> database zabbix <span class="type">character</span> <span class="keyword">set</span> utf8 <span class="keyword">collate</span> utf8_bin;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 创建zabbix@10.70.20.%用户，可由10.70.20.1/24网络下登录</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">user</span> <span class="string">&#x27;zabbix&#x27;</span>@<span class="string">&#x27;10.70.20.%&#x27;</span> identified <span class="keyword">by</span> <span class="string">&#x27;zbx.123&#x27;</span>;</span><br><span class="line"><span class="keyword">grant</span> <span class="keyword">all</span> privileges  <span class="keyword">on</span> zabbix.<span class="operator">*</span> <span class="keyword">to</span> &quot;zabbix&quot;@<span class="string">&#x27;10.70.20.%&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 创建zabbix@172.17.0.%用户，可由172.17.0.1/24网络下登录（zabbix-server/zabbix-web使用docker部署，使用docker网络IP）</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">user</span> <span class="string">&#x27;zabbix&#x27;</span>@<span class="string">&#x27;172.17.0.%&#x27;</span> identified <span class="keyword">by</span> <span class="string">&#x27;zbx.123&#x27;</span>;</span><br><span class="line"><span class="keyword">grant</span> <span class="keyword">all</span> privileges  <span class="keyword">on</span> zabbix.<span class="operator">*</span> <span class="keyword">to</span> &quot;zabbix&quot;@<span class="string">&#x27;172.17.0.%&#x27;</span>;</span><br><span class="line"></span><br><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>

<h2 id="部署zabbix-server及zabbix-web"><a href="#部署zabbix-server及zabbix-web" class="headerlink" title="部署zabbix-server及zabbix-web"></a>部署zabbix-server及zabbix-web</h2><p>zabbix-server及zabbix-web使用docker启动，使用docker部署更快捷，可以省去安装众多依赖包、基础环境的步骤：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动zabbix-server</span></span><br><span class="line">docker run  -e DB_SERVER_HOST=&quot;10.70.20.33&quot; -e DB_SERVER_PORT=&quot;3306&quot; -e MYSQL_USER=&quot;zabbix&quot; -e MYSQL_PASSWORD=&quot;zbx.123&quot; -e MYSQL_DATABASE=&quot;zabbix&quot; -p 10051:10051 --init -d zabbix/zabbix-server-mysql:alpine-5.0.4</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动zabbix-web</span></span><br><span class="line">docker run  -e DB_SERVER_HOST=&quot;10.70.20.33&quot; -e DB_SERVER_PORT=&quot;3306&quot; -e MYSQL_USER=&quot;zabbix&quot; -e MYSQL_PASSWORD=&quot;zbx.123&quot; -e MYSQL_DATABASE=&quot;zabbix&quot; -e ZBX_SERVER_HOST=&quot;10.70.20.33&quot; -e ZBX_SERVER_PORT=&quot;10051&quot; -e PHP_TZ=&quot;Asia/Shanghai&quot; -p 8081:8080  -d zabbix/zabbix-web-nginx-mysql:alpine-5.0.4</span><br></pre></td></tr></table></figure>

<p>环境变量如下：</p>
<ul>
<li>DB_SERVER_HOST，使用的数据库host</li>
<li>DB_SERVER_PORT，使用的数据库port</li>
<li>MYSQL_DATABASE，使用的数据database</li>
<li>MYSQL_USER，连接数据库的user</li>
<li>MYSQL_PASSWORD，连接数据库的password</li>
<li>ZBX_SERVER_HOST，zabbix-server服务的host</li>
<li>ZBX_SERVER_PORT，zabbix-server服务的port</li>
<li>PHP_TZ，设置zabbix-web使用的时区，选用PHP支持的时区</li>
</ul>
<p>这里使用docker部署，并将10051端口映射到了主机的10051端口，因此使用10.70.20.33:10051指定zabbix-server地址；而zabbix-web的容器内8080端口被映射到了主机的8081端口，无他，操作的时候主机的8080端口已被占用了</p>
<p>启动后，查看zabbix-server docker容器日志</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">** Database &#x27;zabbix&#x27; already exists. Please be careful with database COLLATE!</span><br><span class="line">** Creating &#x27;zabbix&#x27; schema in MySQL</span><br></pre></td></tr></table></figure>

<p>可以看到zabbix-server自动完成了zabbix数据表的创建，可以前往数据库确认是否初始化成功</p>
<h3 id="zabbix-web访问路径修改"><a href="#zabbix-web访问路径修改" class="headerlink" title="zabbix-web访问路径修改"></a>zabbix-web访问路径修改</h3><p>启动成功后，zabbix-web默认的访问url为：<a href="http://10.70.20.33:8081，我们可能希望使用：http://10.70.20.33:8081/zabbix">http://10.70.20.33:8081，我们可能希望使用：http://10.70.20.33:8081/zabbix</a></p>
<p>以上使用的zabbix-web-nginx-mysql镜像集成了nginx，可以直接进入容器修改访问根路径：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker <span class="built_in">exec</span>进入zabbix-web容器内</span></span><br><span class="line">docker exec -it &lt;container-id&gt; bash</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入nginx配置文件所在目录</span></span><br><span class="line">cd /etc/nginx</span><br></pre></td></tr></table></figure>

<p>修改&#x2F;etc&#x2F;nginx&#x2F;conf.d&#x2F;nginx.conf文件，将zabbix-web的文件根路径由</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set $webroot &#x27;/usr/share/zabbix&#x27;;</span><br></pre></td></tr></table></figure>
<p>修改为</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set $webroot &#x27;/usr/share&#x27;;</span><br></pre></td></tr></table></figure>

<p>修改后在容器内使用’nginx -s reload’重新加载nginx配置，或者重启容器，即可使用<a target="_blank" rel="noopener" href="http://10.70.20.33:8081/zabbix">http://10.70.20.33:8081/zabbix</a> 访问；容器重启后仍将生效；也可以考虑commit container为image以固化修改，或者改造dockerfile以支持环境变量控制</p>
<h2 id="zabbix-agent部署及配置"><a href="#zabbix-agent部署及配置" class="headerlink" title="zabbix-agent部署及配置"></a>zabbix-agent部署及配置</h2><h3 id="zabbix-agent部署"><a href="#zabbix-agent部署" class="headerlink" title="zabbix-agent部署"></a>zabbix-agent部署</h3><p>以下示例rpm包部署和docker部署</p>
<ol>
<li>rpm包部署</li>
</ol>
<p>下载<a target="_blank" rel="noopener" href="https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.4-1.el7.x86_64.rpm">zabbix-agent 5.0.4 rpm包</a>并安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh --nodeps zabbix-agent-5.0.4-1.el7.x86_64.rpm</span><br><span class="line">zabbix_agentd -V</span><br></pre></td></tr></table></figure>

<p>启动zabbix-agent：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zabbix_agentd</span><br></pre></td></tr></table></figure>

<p>将zabbix-agent添加为开机启动：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">which zabbix_agentd</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">根据<span class="built_in">which</span>命令的输出修改</span></span><br><span class="line">ln -s /usr/sbin/zabbix_agentd /etc/init.d/zabbix_agentd</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>docker部署</li>
</ol>
<p>zabbix-agent同样可以使用docker部署，但需要注意，docker通过ns进行资源隔离——也就是说，zabbix-agent默认采集到的进程、网络等数据，是自己所在的容器挂载的ns下的数据，因此需要在容器启动时挂载主机ns，可参考这个issue <a target="_blank" rel="noopener" href="https://github.com/zabbix/zabbix-docker/issues/764">how to monitor host processes with zabbix 3.4.12 in docker</a></p>
<h3 id="zabbix-agent被动-x2F-主动模式配置"><a href="#zabbix-agent被动-x2F-主动模式配置" class="headerlink" title="zabbix-agent被动&#x2F;主动模式配置"></a>zabbix-agent被动&#x2F;主动模式配置</h3><p>这里的被动、主动是针对zabbix-agent来说的</p>
<p>被动模式是zabbix数据收集的默认模式，即zabbix-server向zabbix-agent发起拉取数据的指令，zabbix-agent将数据返回到zabbix-server；主动模式则是zabbix-agent推送监控数据到zabbix-server</p>
<p>被动模式需要zabbix-server拉取数据，zabbix-agent数量大的情况下压力较大；主动模式需要为每个zabbix-agent指定zabbix-server的地址，并且需要保证地址固定且可用</p>
<p>如果zabbix-server无法访问zabbix-agent的地址（比如，不在同一内网且zabbix-agent无公网IP），那么只能选择主动模式</p>
<ol>
<li>zabbix-agent被动模式配置</li>
</ol>
<p>修改&#x2F;etc&#x2F;zabbix&#x2F;zabbix_agentd.conf，关键项为：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">### Option: LogFileSize</span><br><span class="line">#       Maximum size of log file in MB.</span><br><span class="line">#       0 - disable automatic log rotation.</span><br><span class="line">#</span><br><span class="line"># Mandatory: no</span><br><span class="line"># Range: 0-1024</span><br><span class="line"># Default:</span><br><span class="line"># LogFileSize=1</span><br><span class="line"></span><br><span class="line"># 修改LogFileSize，设置日志文件大小</span><br><span class="line">LogFileSize=1024</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">### Option: Server</span><br><span class="line">#       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.</span><br><span class="line">#       Incoming connections will be accepted only from the hosts listed here.</span><br><span class="line">#       If IPv6 support is enabled then &#x27;127.0.0.1&#x27;, &#x27;::127.0.0.1&#x27;, &#x27;::ffff:127.0.0.1&#x27; are treated equally</span><br><span class="line">#       and &#x27;::/0&#x27; will allow any IPv4 or IPv6 address.</span><br><span class="line">#       &#x27;0.0.0.0/0&#x27; can be used to allow any IPv4 address.</span><br><span class="line">#       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com</span><br><span class="line">#</span><br><span class="line"># Mandatory: yes, if StartAgents is not explicitly set to 0</span><br><span class="line"># Default:</span><br><span class="line"># Server=</span><br><span class="line"></span><br><span class="line"># zabbix-server/zabbix-proxy的地址，可以指定多个；如果不固定可以按照注释设置为子网范围，zabbix-agent将只允许范围Server指定的IP/子网范围内的请求</span><br><span class="line"># 这里放行了zabbix-server所在主机IP和所在容器内网IP，可以查看docker0网卡确认容器子网范围</span><br><span class="line">Server=10.70.20.33,172.17.0.1/16</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">### Option: Hostname</span><br><span class="line">#       Unique, case sensitive hostname.</span><br><span class="line">#       Required for active checks and must match hostname as configured on the server.</span><br><span class="line">#       Value is acquired from HostnameItem if undefined.</span><br><span class="line">#</span><br><span class="line"># Mandatory: no</span><br><span class="line"># Default:</span><br><span class="line"># Hostname=</span><br><span class="line"># zabbix-agent在zabbix-server中使用的hostname，可以指定为所在主机的IP方便识别</span><br><span class="line">Hostname=10.70.20.20</span><br></pre></td></tr></table></figure>

<p>启动zabbix-agent：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zabbix_agentd</span><br></pre></td></tr></table></figure>
<p>按照配置文件指定的日志路径（默认为&#x2F;var&#x2F;log&#x2F;zabbix&#x2F;zabbix_agentd.log）查看启动是否成功</p>
<ol start="2">
<li>zabbix-agent主动模式配置</li>
</ol>
<p>修改&#x2F;etc&#x2F;zabbix&#x2F;zabbix_agentd.conf，关键项为：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line">### Option: LogFileSize</span><br><span class="line">#       Maximum size of log file in MB.</span><br><span class="line">#       0 - disable automatic log rotation.</span><br><span class="line">#</span><br><span class="line"># Mandatory: no</span><br><span class="line"># Range: 0-1024</span><br><span class="line"># Default:</span><br><span class="line"># LogFileSize=1</span><br><span class="line"></span><br><span class="line"># 修改LogFileSize，设置日志文件大小</span><br><span class="line">LogFileSize=1024</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">### Option: Server</span><br><span class="line">#       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.</span><br><span class="line">#       Incoming connections will be accepted only from the hosts listed here.</span><br><span class="line">#       If IPv6 support is enabled then &#x27;127.0.0.1&#x27;, &#x27;::127.0.0.1&#x27;, &#x27;::ffff:127.0.0.1&#x27; are treated equally</span><br><span class="line">#       and &#x27;::/0&#x27; will allow any IPv4 or IPv6 address.</span><br><span class="line">#       &#x27;0.0.0.0/0&#x27; can be used to allow any IPv4 address.</span><br><span class="line">#       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com</span><br><span class="line">#</span><br><span class="line"># Mandatory: yes, if StartAgents is not explicitly set to 0</span><br><span class="line"># Default:</span><br><span class="line"># Server=</span><br><span class="line"></span><br><span class="line"># zabbix-server/zabbix-proxy的地址，可以指定多个；如果不固定可以按照注释设置为子网范围，zabbix-agent将只允许范围Server指定的IP/子网范围内的请求</span><br><span class="line"># 这里放行了zabbix-server所在主机IP和所在容器内网IP，可以查看docker0网卡确认容器子网范围</span><br><span class="line">Server=10.70.20.33,172.17.0.1/16</span><br><span class="line"></span><br><span class="line">### Option: StartAgents</span><br><span class="line">#       Number of pre-forked instances of zabbix_agentd that process passive checks.</span><br><span class="line">#       If set to 0, disables passive checks and the agent will not listen on any TCP port.</span><br><span class="line">#</span><br><span class="line"># Mandatory: no</span><br><span class="line"># Range: 0-100</span><br><span class="line"># Default:</span><br><span class="line"># StartAgents=3</span><br><span class="line"></span><br><span class="line"># 调整为0，关闭zabbix-agent被动模式，zabbix-agent也将不监听任何端口</span><br><span class="line">StartAgents=0</span><br><span class="line"></span><br><span class="line">### Option: ServerActive</span><br><span class="line">#       List of comma delimited IP:port (or DNS name:port) pairs of Zabbix servers and Zabbix proxies for active checks.</span><br><span class="line">#       If port is not specified, default port is used.</span><br><span class="line">#       IPv6 addresses must be enclosed in square brackets if port for that host is specified.</span><br><span class="line">#       If port is not specified, square brackets for IPv6 addresses are optional.</span><br><span class="line">#       If this parameter is not specified, active checks are disabled.</span><br><span class="line">#       Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]</span><br><span class="line">#</span><br><span class="line"># Mandatory: no</span><br><span class="line"># Default:</span><br><span class="line"># ServerActive=</span><br><span class="line"></span><br><span class="line"># zabbix-server/zabbix-proxy的地址，可以指定多个，用于指定zabbix-agent推送数据的地址</span><br><span class="line">ServerActive=10.70.20.33:10051</span><br><span class="line"></span><br><span class="line">### Option: Hostname</span><br><span class="line">#       Unique, case sensitive hostname.</span><br><span class="line">#       Required for active checks and must match hostname as configured on the server.</span><br><span class="line">#       Value is acquired from HostnameItem if undefined.</span><br><span class="line">#</span><br><span class="line"># Mandatory: no</span><br><span class="line"># Default:</span><br><span class="line"># Hostname=</span><br><span class="line"># zabbix-agent在zabbix-server中使用的hostname，可以指定为所在主机的IP方便识别</span><br><span class="line">Hostname=10.70.20.20</span><br></pre></td></tr></table></figure>

<h2 id="zabbix-server添加监控项"><a href="#zabbix-server添加监控项" class="headerlink" title="zabbix-server添加监控项"></a>zabbix-server添加监控项</h2><p>在zabbix-web添加host，为host关联templete；也可通过zabbix提供的Discovery定义配置自动发现</p>
<p>在此不演示，可以参考<a target="_blank" rel="noopener" href="https://www.zabbix.com/documentation/3.4/zh/manual/config/hosts">zabbix文档</a>或者网络资料如：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/huibaobao/p/13537759.html">zabbix agent的主动模式配置</a></p>
<p>添加主机监控后，查看zabbix-agent、zabbix-server日志，确认是否成功获取监控数据，在zabbix-web也可以看到zabbix-agent状态</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/zabbix/" rel="tag"># zabbix</a>
              <a href="/tags/%E7%9B%91%E6%8E%A7/" rel="tag"># 监控</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/31e339ac.html" rel="prev" title="Spring Boot读取 Resource 资源文件">
      <i class="fa fa-chevron-left"></i> Spring Boot读取 Resource 资源文件
    </a></div>
      <div class="post-nav-item">
    <a href="/919d4f23.html" rel="next" title="Spring security 登陆认证的重要概念、流程梳理及自定义设置">
      Spring security 登陆认证的重要概念、流程梳理及自定义设置 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#mysql%E9%83%A8%E7%BD%B2%E4%B8%8E%E9%85%8D%E7%BD%AE"><span class="nav-number">1.</span> <span class="nav-text">mysql部署与配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%83%A8%E7%BD%B2zabbix-server%E5%8F%8Azabbix-web"><span class="nav-number">2.</span> <span class="nav-text">部署zabbix-server及zabbix-web</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#zabbix-web%E8%AE%BF%E9%97%AE%E8%B7%AF%E5%BE%84%E4%BF%AE%E6%94%B9"><span class="nav-number">2.1.</span> <span class="nav-text">zabbix-web访问路径修改</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#zabbix-agent%E9%83%A8%E7%BD%B2%E5%8F%8A%E9%85%8D%E7%BD%AE"><span class="nav-number">3.</span> <span class="nav-text">zabbix-agent部署及配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#zabbix-agent%E9%83%A8%E7%BD%B2"><span class="nav-number">3.1.</span> <span class="nav-text">zabbix-agent部署</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#zabbix-agent%E8%A2%AB%E5%8A%A8-x2F-%E4%B8%BB%E5%8A%A8%E6%A8%A1%E5%BC%8F%E9%85%8D%E7%BD%AE"><span class="nav-number">3.2.</span> <span class="nav-text">zabbix-agent被动&#x2F;主动模式配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#zabbix-server%E6%B7%BB%E5%8A%A0%E7%9B%91%E6%8E%A7%E9%A1%B9"><span class="nav-number">4.</span> <span class="nav-text">zabbix-server添加监控项</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">马天</p>
  <div class="site-description" itemprop="description">程序猿</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">41</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">17</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/matian2014" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;matian2014" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:matian1103@qq.com" title="E-Mail → mailto:matian1103@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">陕ICP备2023001563号 </a>
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2025</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">马天</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
